// 引入全局样式
import { dynamicCSS } from './dynamicCss.js';
dynamicCSS('/css/common.css');

// 引入接口调用的格式化方法
import { request } from './request.js';

// 默认参数获取方法
import { optionSide } from './optionSide.js';

// 表单组件
import { form } from './form.js';


var _form = new form({
    type: 'onlyChange'
});
_form.setOptions([
    {
        key: 'input',
        type: 'input',
        box: {
            lable: '单行文本',
            annotate: '单行文本测试注释',
            size: 'middle',
            className: '',
        },
        element: {
            verify: {  // 验证判断组
                text: '单行文本输入框',
                rules: function (value) {
                    return '错误'
                }
            },
        }
    }, {
        key: 'password',
        type: 'password',
        box: {
            lable: '密码',
            annotate: '密码输入框',
            size: 'middle',
            className: '',
        },
        element: {
            verify: {  // 验证判断组
                text: '单行文本输入框',
                rules: function (value) {
                    return false
                }
            },
        }
    }, {
        key: 'textarea',
        type: 'textarea',
        box: {
            lable: '多行文本',
            annotate: '多行文本测试注释',
            size: 'middle',
            className: '',
        },
        element: {}
    }, {
        key: 'select',
        type: 'select',
        box: {
            lable: '下拉菜单',
            annotate: '下拉菜单测试注释',
            size: 'middle',
            className: '',
        },
        element: {
            data: 'OptionSide:sex',
            showKey: 'name'
        }
    }, {
        key: 'inputDate',
        type: 'inputDate',
        box: {
            lable: '日期选择器',
            annotate: '日期选择器测试注释',
            size: 'middle',
            className: '',
        },
        element: {}
    }, {
        key: 'checkBox',
        type: 'checkBox',
        box: {
            lable: '多选框',
            annotate: '多选框测试注释',
            size: 'middle',
            className: '',
        },
        element: {
            element: [{
                key: 'test1',
                className: '',
                name: '测试1',
            }, {
                key: 'test2',
                className: '',
                name: '测试2',
            }, {
                key: 'test3',
                className: '',
                name: '测试3',
            }],
        }
    }, {
        key: 'radio',
        type: 'radio',
        box: {
            lable: '单选框',
            annotate: '单选框测试注释',
            size: 'middle',
            className: '',
        },
        element: {
            data: 'OptionSide:sex',
            showKey: 'name'
        }
    }
]);

$('body').append(_form.html);

_form.setData({
    id: 'xxxxx',
    input: 'aaa',
    textarea: 'bbb',
    select: 2,
    inputDate: '1989/09/22',
    checkBox: {
        test2: true,
    },
    radio: 2,
});

setInterval(function () {
    var ans = _form.get();
    if (ans) {
        console.log(ans);
    } else {
        console.log(_form.errorMessage);
    };
}, 5000);




// 获取单个表单元素
// console.log(_form.getFormObject('input', {}));
window.form = _form

// console.log();




